package com.ilink.teacherservice.config;

/**
 * <h3>new-ilink-java-backend</h3>
 *
 * @Description <p>依赖application dev配置文件，去构建的线程池配置</p>
 * @Author pengshiyao
 * @Date 2024-09-16 14:12
 **/

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
 * @ClassName ThreadPoolConfig
 * @Description
 * @Author pengshiyao
 * @Date 2024-09-16 14:12
 **/
@Configuration
@RefreshScope
public class ThreadPoolConfig {

    @Value("${ilink.threadpool.fileUpload.corePoolSize:10}")
    private int fileUploadCorePoolSize;

    @Value("${ilink.threadpool.fileUpload.maxPoolSize:25}")
    private int fileUploadMaxPoolSize;

    @Value("${ilink.threadpool.fileUpload.keepAliveTime:60}")
    private long fileUploadKeepAliveTime;

    @Value("${ilink.threadpool.fileUpload.queueCapacity:5000}")
    private int fileUploadQueueCapacity;

    @Value("${ilink.threadpool.fileHandle.corePoolSize:5}")
    private int fileHandleCorePoolSize;

    @Value("${ilink.threadpool.fileHandle.maxPoolSize:15}")
    private int fileHandleMaxPoolSize;

    @Value("${ilink.threadpool.fileHandle.keepAliveTime:60}")
    private long fileHandleKeepAliveTime;

    @Value("${ilink.threadpool.fileHandle.queueCapacity:5000}")
    private int fileHandleQueueCapacity;

    @Value("${ilink.threadpool.checkVideo.corePoolSize:1}")
    private int checkVideoCorePoolSize;

    @Value("${ilink.threadpool.checkVideo.maxPoolSize:5}")
    private int checkVideoMaxPoolSize;

    @Value("${ilink.threadpool.checkVideo.keepAliveTime:60}")
    private long checkVideoKeepAliveTime;

    @Value("${ilink.threadpool.checkVideo.queueCapacity:5000}")
    private int checkVideoQueueCapacity;

    @Value("${ilink.threadpool.videoHandle.corePoolSize:5}")
    private int videoHandleCorePoolSize;

    @Value("${ilink.threadpool.videoHandle.maxPoolSize:10}")
    private int videoHandleMaxPoolSize;

    @Value("${ilink.threadpool.videoHandle.keepAliveTime:60}")
    private long videoHandleKeepAliveTime;

    @Value("${ilink.threadpool.videoHandle.queueCapacity:5000}")
    private int videoHandleQueueCapacity;

    // 文档上传对应的线程池
    @Bean(name = "fileUploadTaskExecutor")
    public ThreadPoolExecutor fileUploadTaskExecutor() {
        return new ThreadPoolExecutor(fileUploadCorePoolSize, fileUploadMaxPoolSize, fileUploadKeepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<>(fileUploadQueueCapacity));
    }

    // 文档处理对应的线程池
    @Bean(name = "fileHandleTaskExecutor")
    public ThreadPoolExecutor fileHandleTaskExecutor() {
        return new ThreadPoolExecutor(fileHandleCorePoolSize, fileHandleMaxPoolSize, fileHandleKeepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<>(fileHandleQueueCapacity));
    }

    // 音视频转写回调状态查询的线程池
    @Bean(name = "checkVideoTaskExecutor")
    public ThreadPoolExecutor checkVideoTaskExecutor() {
        return new ThreadPoolExecutor(checkVideoCorePoolSize, checkVideoMaxPoolSize, checkVideoKeepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<>(checkVideoQueueCapacity));
    }

    // 音视频加工的线程池
    @Bean(name = "videoHandleTaskExecutor")
    public ThreadPoolExecutor videoHandleTaskExecutor() {
        return new ThreadPoolExecutor(videoHandleCorePoolSize, videoHandleMaxPoolSize, videoHandleKeepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<>(videoHandleQueueCapacity));
    }
}
